<template>
	<Container>
		<view class="header">
			<view class="header-content" :style="{ background: 'url(' + assignment.backgroundUrl + ') 0 0 /100% 100%' }"><Article :articles="assignment.articles" /></view>
			<AudioIcon @iconTap="iconTap" :questionPress="questionPress" />
		</view>
		<Question :question="assignment.questionName" />
		<view class="articleBox">
			<view
				@tap="tap(item, index)"
				class="articles"
				v-for="(item, index) in assignment.optionArticles"
				:style="{ left: articleStyle[index].left, top: articleStyle[index].top, transform: 'scale(' + articleStyle[index].scale + ')' }"
				:key="index"
			>
				<view class="box" :class="{ success: chooses[index] === 'select' || chooses[index] === 'success', error: chooses[index] === 'error' }">
					<image class="item" mode="aspectFit" :src="item.imageUrl"></image>
					<SuccessIcon v-if="chooses[index] === 'success'" />
					<text class="name">{{ item.name }}</text>
				</view>
			</view>
		</view>
	</Container>
</template>

<script>
import { mixins } from '../../../common/mixins/assignmentDefault.js'
import Article from '../article.vue'
import AudioIcon from '../audioIcon.vue'
import Question from '../questionName.vue'
import Container from '../container.vue'
import SuccessIcon from '../successIcon.vue'
export default {
	data() {
		return {
			articleStyle: [{ left: '0', top: '0', scale: 1 }, { left: '50%', top: '0', scale: 1 }, { left: '0', top: '50%', scale: 1 }, { left: '50%', top: '50%', scale: 1 }],
		}
	},
	components: { Article, AudioIcon, Question, Container, SuccessIcon },
	mixins: [mixins],
	methods: {
		tap: function(item, index) {
			this.touchAudio()
			if (this.isComplete) return
			if (this.chooses[index] === 'select') {
				this.optionStatus('', index)
			} else {
				this.optionStatus('select', index)
				if (this.choosesKey.indexOf(index) < 0) this.choosesKey.push(index)
			}
			if (this.choosesKey.length === 2) {
				this.isComplete = true
				const bool = this.choosesKey.every(item => {
					return this.assignment.optionArticles[item].isMatched
				})
				if (bool) {
					this.choosesKey.map(item => {
						this.optionStatus('success', item)
					})
					this.articleStyle[this.choosesKey[0]].top = '25%'
					this.articleStyle[this.choosesKey[0]].left = '0'
					this.articleStyle[this.choosesKey[1]].top = '25%'
					this.articleStyle[this.choosesKey[1]].left = '50%'
					this.assignment.optionArticles.map((item, current) => {
						if (this.choosesKey.indexOf(current) < 0) {
							this.articleStyle[current].scale = 0
						}
					})
					this.$parent.next({
						isSure: true
					})
				} else {
					this.choosesKey.map(item => {
						this.optionStatus('error', item)
					})
					this.$parent.next()
				}
			}
		}
	}
}
</script>

<style scoped lang="stylus">
.header
	height 45vh
	width 100%
	overflow hidden
	border-radius 70rpx
	border 12rpx solid #FCC77D
	box-sizing border-box
	transform translate3d(0, 0, 0)
	position relative
	margin 5vh 0 2vh 0
	.header-content
		position absolute
		height 100%
		width 1080rpx
		left 50%
		top 50%
		transform translate3d(-50%, -50%, 0)
		z-index 98
.articleBox
	width 100%
	height 43vh
	display flex
	flex-wrap wrap
	justify-content center
	align-items center
	position relative
	.articles
		width 50%
		height 50%
		max-height 23vh
		font-size 34rpx
		transition all 0.5s
		color #FFC268
		flex-direction column
		align-items center
		display flex
		position absolute
		.box
			transition all 0.5s
			border 12rpx solid #FFC268
			border-radius 60rpx
			width 80%
			max-width 25vh
			height 70%
			position relative
			flex-direction column
			align-items center
			display flex
			justify-content center
			.name
				position absolute
				bottom -50rpx
			.item
				height 80%
				width 70%
				filter drop-shadow(2px 0px #fff) drop-shadow(-2px 0px #fff) drop-shadow(0px -2px #fff) drop-shadow(0px 2px #fff) drop-shadow(2px 2px 1px #0000004a)
</style>
